package cc.lj.internal.api.ordershare.api.fallbackfactory;

import cc.lj.internal.api.ordershare.api.OrderOnlineFeignService;
import cc.lj.internal.api.ordershare.dto.OrderOnlineAPIDTO;
import cc.lj.internal.core.http.HttpResult;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 *  电子券分摊结算数据查询fegin回退处理，可以打印出具体回退原因
 *  注意：只有配置文件中开启hystrix (feign.hystrix.enabled=true),该配置才会起作用
 * @author liangxifeng
 * @date 2023/6/25 15:11
 */

@Slf4j
@Component
public class OrderOnlineFeignServiceFallbackFactory implements FallbackFactory<OrderOnlineFeignService> {
    @Override
    public OrderOnlineFeignService create(Throwable cause) {
        return new OrderOnlineFeignService() {
            @Override
            public HttpResult<OrderOnlineAPIDTO> getByPactNum(String pactNum) {
                log.error("feign--请求公有库模块ordershare:通过合同号查询订单数据出现异常,原因:" + cause.getMessage());
                return new HttpResult<>(HttpResult.SERVICE_FUSING.getCode(), HttpResult.SERVICE_FUSING.getMessage());
            }
        };
    }
}
